# -*- coding:utf-8 -*-
import jieba
from matplotlib import pyplot as plt
from wordcloud import WordCloud
from PIL import Image
import numpy as np
import sqlite3

connect = sqlite3.connect("movie.db")
cur = connect.cursor()
sql = "SELECT introduction FROM movie250"

data = cur.execute(sql)
text = ""
for item in data:
    text = text + item[0]
# print(text)

cut = jieba.cut(text)

string = ' '.join(cut)
# print(string)
# print(len(string))

a = Image.open(r'.\static\image\jt.png')
img = Image.open(r'.\static\image\img.jpg')
a = np.array(a)
img_arr = np.array(img)

wc = WordCloud(
    background_color='white',
    mask = img_arr,
    font_path = 'simkai.ttf',
)
wc.generate_from_text(string)

wc1 = WordCloud(
    background_color='white',
    mask = a,
    font_path = 'simkai.ttf',
)
wc1.generate_from_text(string)

# 绘制图片
fig     = plt.figure(1)
plt.imshow(wc1)
plt.axis('off')

# plt.show()
plt.savefig(r'.\static\image\wordjt.jpg',dpi=500)

